/**
 * Copyleft (C) 2023-2024 maminjie <canpool@163.com>
 * SPDX-License-Identifier: BSD-3-Clause
 **/
#ifndef QXMATERIALSCROLLBAR_P_H
#define QXMATERIALSCROLLBAR_P_H

#include "qxmaterial_global.h"
#include <QColor>
#include <QStateMachine>
#include "matscrollbar.h"

QX_MATERIAL_BEGIN_NAMESPACE

class MatScrollBar;
class MatScrollBarStateMachine;

class MatScrollBarPrivate
{
    Q_DISABLE_COPY(MatScrollBarPrivate)
    Q_DECLARE_PUBLIC(MatScrollBar)
public:
    MatScrollBarPrivate(MatScrollBar *q);
    ~MatScrollBarPrivate();

    void init();

    MatScrollBar *const q_ptr;
    MatScrollBarStateMachine *stateMachine;
    QColor backgroundColor;
    QColor sliderColor;
    QColor canvasColor;
    bool hideOnMouseOut;
    bool useThemeColors;
};

class MatScrollBarStateMachine : public QStateMachine
{
    Q_OBJECT

    Q_PROPERTY(qreal opacity WRITE setOpacity READ opacity)
public:
    MatScrollBarStateMachine(MatScrollBar *parent);
    ~MatScrollBarStateMachine();

    inline void setOpacity(qreal opacity);
    inline qreal opacity() const;
private:
    Q_DISABLE_COPY(MatScrollBarStateMachine)

    MatScrollBar *const m_scrollBar;
    QState *const m_focusState;
    QState *const m_blurState;
    qreal m_opacity;
};

inline void MatScrollBarStateMachine::setOpacity(qreal opacity)
{
    m_opacity = opacity;
    m_scrollBar->update();
}

inline qreal MatScrollBarStateMachine::opacity() const
{
    return m_opacity;
}

QX_MATERIAL_END_NAMESPACE

#endif   // QXMATERIALSCROLLBAR_P_H
